//
//  BBImageButtonFactory.m
//  xNose
//
//  Created by ben smith on 16/09/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "BBImageButtonFactory.h"
#import "BBTUIOButton.h"

@implementation BBImageButtonFactory


// simply generates a button from some images
+(NSButton*)imageButtonInRect:(NSRect)rect withImageName:(NSString*)imageName
{
	// grab the named png image
	NSImage * ximage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];

	// make a button
	BBTUIOButton * myButton = [[BBTUIOButton alloc] initWithFrame:rect];
	[myButton setBordered:NO];
	[myButton setBezelStyle:NSCircularBezelStyle];
	// turn off the ugly highlighting
	[[myButton cell] setHighlightsBy:NSContentsCellMask];
	// fit my image to the frame
	[[myButton cell] setImageScaling:NSScaleToFit];
	
	[myButton setImage:ximage];
	
	// now make another image, but just a bit differnet so we
	// get a nice mouseDown look. the easy thing to do 
	// is just to xor the image with itself
	NSImage * alt = [ximage copy];
	[alt lockFocus];
	NSSize size = [ximage size];
	NSRect imageRect = NSMakeRect(0, 0, size.width, size.height);
	[alt drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeXOR fraction:0.5];
	[alt unlockFocus];
	
	[myButton setAlternateImage:alt];
	
	[alt release];
	[ximage release];
	return [myButton autorelease];
}

+(NSButton*)transparentButtonInRect:(NSRect)rect
{
	// make a button
	BBTUIOButton * myButton = [[BBTUIOButton alloc] initWithFrame:rect];
	[myButton setTransparent:YES];
	return [myButton autorelease];	
}

+(NSButton*)bigChartButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"minichartbigger"];
}

+(NSButton*)smallChartButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"minichart"];
}

+(NSButton*)checkButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"check"];
}

+(NSButton*)infoButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"info"];
}

+(NSButton*)closeButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"xbutton"];
}

+(NSButton*)connectionButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"connectButton"];
}

+(NSButton*)magnifierButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"magnifier"];
}

+(NSButton*)quitButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"quit"];
}

+(NSButton*)bulbButtonInRect:(NSRect)rect
{
	return [BBImageButtonFactory imageButtonInRect:rect withImageName:@"bulb"];
}

// just like the imagebutton above, but with two specific images
+(NSButton*)disclosureButtonInRect:(NSRect)rect
{
	// this one is a bit different
	NSImage *minus = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"minus" ofType:@"png"]];
	NSImage *plus = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"plus" ofType:@"png"]];

	BBTUIOButton * myButton = [[BBTUIOButton alloc] initWithFrame:rect];
	[myButton setButtonType:NSToggleButton];
	[myButton setBordered:NO];
	[[myButton cell] setHighlightsBy:NSContentsCellMask];
	[[myButton cell] setImageScaling:NSScaleToFit];
	
	[myButton setImage:plus];
	
	[myButton setAlternateImage:minus];
	[minus release];
	[plus release];
	return [myButton autorelease];	
}

// just like the imagebutton above, but with two specific images
+(NSButton*)openCloseButtonInRect:(NSRect)rect
{
	// this one is a bit different
	NSImage *open = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"openTab" ofType:@"png"]];
	NSImage *close = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"closeTab" ofType:@"png"]];
	
	BBTUIOButton * myButton = [[BBTUIOButton alloc] initWithFrame:rect];
	[myButton setButtonType:NSToggleButton];
	[myButton setBordered:NO];
	[[myButton cell] setHighlightsBy:NSContentsCellMask];
	[[myButton cell] setImageScaling:NSScaleToFit];
	
	[myButton setImage:open];
	
	[myButton setAlternateImage:close];
	[close release];
	[open release];
	return [myButton autorelease];	
}


@end
